<%--
  Created by IntelliJ IDEA.
  User: lixiaodong
  Date: 2018/4/3
  Time: 16:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div id="user_dialog" class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center'">
        <form id="user_add_form">
            <input type="hidden" id="user_add_id" name="user.id">
            <table class="table1" style="width: 100%">
                <tr>
                    <th>关联人员信息：</th>
                    <td>
                        <input id="user_add_person" name="personNumber" required/>
                    </td>
                </tr>
                <tr>
                    <th>角色：</th>
                    <td>
                        <input id="user_add_role" name="roleNumbers" required/>
                    </td>
                </tr>
                <tr class="user_add_psd_tr">
                    <th>密码：</th>
                    <td>
                        <input id="user_add_password" class="easyui-textbox easyui-passwordbox" name="user.password" data-options="required:true">
                    </td>
                </tr>
                <tr class="user_add_psd_tr">
                    <th>确认密码：</th>
                    <td>
                        <input id="user_add_password0" class="easyui-textbox easyui-passwordbox" name="password0" data-options="required:true">
                    </td>
                </tr>
                <tr>
                    <th>状态：</th>
                    <td>
                        <input id="user_add_state" class="easyui-textbox" name="user.state" data-options="required:false">
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <div data-options="region:'south'" style="height: 50px;padding-top: 10px;">
        <div style="position: absolute; right: 20px">
            <a href="javascript:;" id="user_add_ok" class="easyui-linkbutton" data-options="iconCls:'fa fa-check'" style="margin-right: 10px">确 定</a>
            <a href="javascript:;" id="user_add_cancel" class="easyui-linkbutton" data-options="iconCls:'fa fa-times'">关 闭</a>
        </div>
    </div>
</div>

<script type="text/javascript">
    var _user_add_js = {
        _qp:null,
        load_person : function () {
            var _columns = [[
                {field:'name',title:'姓名',width:150},
                {field:'number',title:'编号',width:150}
            ]];
            var _url = bs.base_url + 'person/getAll.action';
            bs.load_category('user_add_person', _columns, _url, 'number', 'name');
        },
        load_role : function () {
            var _columns = [[
                {field:'name',title:'角色名称',width:150},
                {field:'number',title:'角色编号',width:150}
            ]];
            var _url = bs.base_url + 'role/getAll.action';
            bs.load_category('user_add_role', _columns, _url, 'number', 'name');
        },
        init:function () {
            _user_add_js.load_person();
            _user_add_js.load_role();
            _user_add_js._qp = $('#user_dialog').dialog('options').queryParams;
            if (_user_add_js._qp.flag == 'add'){

            }else if (_user_add_js._qp.flag == 'update'){
                $('.user_add_psd_tr').html('');
                if (_user_add_js._qp.row != null){
                    var _row = _user_add_js._qp.row;
                    $('#user_add_id').val(_row.id);
                    $('#user_add_state').textbox('setValue',_row.state);
                    if (_row.person != null){
                        $("#user_add_person").combogrid('setValue',_row.person.number);
                    }
                }
            }
        },
        btn_init:function () {
            $('#user_add_cancel').on('click',function () {
                $("#user_dialog").dialog('destroy');
            });
            $('#user_add_ok').on('click',function () {
                if ($('#user_add_password').value !== $('#user_add_password0').value){
                    $.messager.alert('警告','两次密码不一致');
                    return;
                }
                var _url = '';
                if (_user_add_js._qp.flag == 'add'){
                    _url = bs.base_url + 'user/add.action';
                }else if (_user_add_js._qp.flag == 'update'){
                    _url = bs.base_url + 'user/update.action';
                }
                bs.formSubmit_datagrid(_url,'user_add_form','user_dialog','user_index_dg_user');
            });
        }
    }

    var user_add_app = (function () {
        $(function () {
            _user_add_js.init();
            _user_add_js.btn_init();
        });
    })();
</script>